package com.gf.user.dao.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.gf.base.dao.impl.BaseDaoImpl;
import com.gf.user.dao.IdolFanDao;

@Service("idolFanDao")
public class IdolFanDaoImpl extends BaseDaoImpl implements IdolFanDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	/**
	 * insert into idolfan (userId,userName,createtime) values (?,(select
	 * nickname from user where id=?),current_timestamp)
	 */
	@Value("${idolFanDao.insertIdolFanSql}")
	private String insertIdolFanSql;

	/**
	 * update idolfan set idolIds=? where userId=?
	 */
	@Value("${idolFanDao.insertIdolSql}")
	private String insertIdolSql;

	/**
	 * update idolfan set fanIds=? where userId=?
	 */
	@Value("${idolFanDao.insertFanSql}")
	private String insertFanSql;

	/**
	 * select (idolIds) from idolfan where userId=?
	 */
	@Value("${idolFanDao.queryIdolsSql}")
	private String queryIdolsSql;

	/**
	 * select (fanIds) from idolfan where userId=?
	 */
	@Value("${idolFanDao.queryFansSql}")
	private String queryFansSql;

	@Override
	public void insertIdolFan(long userId) {
		this.insertWithIdReturn(insertIdolFanSql, userId, userId);
	}

	@Override
	public boolean updateIdol(long userId, String idolIds) {
		int updateCount = jdbcTemplate.update(insertIdolSql, idolIds, userId);
		if (updateCount == 0) {
			return false;
		}
		return true;
	}

	@Override
	public boolean updateFan(long userId, String fanIds) {
		int updateCount = jdbcTemplate.update(insertFanSql, fanIds, userId);
		if (updateCount == 0) {
			return false;
		}
		return true;
	}

	@Override
	public String queryIdols(long userId) {
		return jdbcTemplate.queryForObject(queryIdolsSql, String.class, userId);
	}

	@Override
	public String queryFans(long userId) {
		return jdbcTemplate.queryForObject(queryFansSql, String.class, userId);
	}

}
